package view
{
	import com.tb.sng.view.ViewComponent;
	
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	import res.mc_reg_type;
	
	public class RegView extends ViewComponent
	{
		public var mc:mc_reg_type;
		
		public function RegView()
		{
			mc = new mc_reg_type();
			
			mc.x = 268;
			mc.y = 75;
			
			mc.txt_password.displayAsPassword = true;
			mc.txt_password2.displayAsPassword = true;
			
			mc.txt_username.text = "";
			mc.txt_password.text = "";
			mc.txt_password2.text = "";
			
			mc.txt_username.maxChars = 30;
			
			mc.btn_reg.addEventListener(MouseEvent.CLICK, regHandler);
			mc.btn_close.addEventListener(MouseEvent.CLICK, closeHandler);
			
			mc.btn_reg.tabEnabled = false;
			mc.btn_close.tabEnabled = false;
			
			var mask:Sprite = new Sprite();
			mask.graphics.beginFill(0x0, 0.2);
			mask.graphics.drawRect(0,0, 900, 580);
			mask.graphics.endFill();
			
			addChild(mask);
			
			addChild(mc);
		}
		
		private function regHandler(e:MouseEvent):void
		{
			var username:String = mc.txt_username.text;
			var password:String = mc.txt_password.text;
			
			if (username.length < 5){
				Dialog.show("账号至少5位字符");
				return;
			}
			
			if (password.length < 5){
				Dialog.show("密码至少5位字符");
				return;
			}
			
			if (password != mc.txt_password2.text){
				Dialog.show("两次密码不一致");
				return;
			}
			
			callMethod("doreg", username, password);
		}
		
		private function closeHandler(e:MouseEvent):void
		{
			callMethod("close");
		}
	}
}